﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using XGE.ComponentSystem;
namespace XGE.Graphics
{
    public class Sprite : IDrawableObject
    {
        protected ICoreGame Game;
        public int columns = 1;
        public int rows = 1;
        protected bool enabled;
        public string textureName;
        public Texture2D texture;
        public float layer = 0.0f;
        public bool animated;
        private SpriteAnimation currentAnimation;
        public Dictionary<string, SpriteAnimation> animations = new Dictionary<string, SpriteAnimation>();        
        private TimeSpan updateLength;
        private Vector2 position = Vector2.Zero;
        public Vector2 Position
        {
            get { return position; }
            set { position = value; }
        }
        private Color textureColor = Color.White;
        /// <summary>
        /// Set the color of the sprite.
        /// Default is White.
        /// </summary>
        public Color TextureColor
        {
            get { return textureColor; }
            set { textureColor = value; }
        }
        
        public Sprite(string Texture, Vector2 Position, float Layer)
            : this(Texture, Position)
        {
            layer = Layer;
        }

        public Sprite(string Texture, Vector2 Position)
            : this(Texture)
        {
            position = Position;
        }

        public Sprite(string Texture)
        {
            textureName = Texture;
        }
        #endregion

        public virtual void Initialize()
        {
        }
        public void AddGame(ICoreGame game)
        {
            this.Game = game;
        }

        public virtual void LoadContent()
        {
            texture = Game.Content.Load<Texture2D>(textureName);
        }

        public virtual void Update(GameTime gameTime)
        {
        }

        public virtual void Draw(GameTime gameTime)
        {
            Game.spriteBatch.Draw(texture, position, Color.White);
        }

        public void AddAnimation(SpriteAnimation ANIMATION)
        {
            animations.Add(ANIMATION.animationName, ANIMATION);
        }

        #region IDrawableObject Members

        bool IDrawableObject.isEnabled
        {
            get { return enabled; }
        }

        #endregion
    }
}
